package com.nifostasky.comic.vos;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel(description = "分页返回结果")
public class JsonResult<T> implements Serializable {

    @ApiModelProperty("状态code")
    private int code = 200;

    @ApiModelProperty("状态信息")
    private String msg = "success";

    @ApiModelProperty("返回值")
    private T data;

    public JsonResult() {
    }

    public JsonResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public JsonResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public JsonResult(T data) {
        this.data = data;
    }

    public JsonResult(ResultCode data) {
        this.code = data.getCode();
        this.msg = data.getMsg();
    }

    public <V> JsonResult(IPage<V> page) {
        this.data = (T) new PageResult<V>(page);
    }
}
